package net.wanho.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.wanho.po.Emp;
import net.wanho.service.EmpService;
import net.wanho.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import java.io.Serializable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 员工表 前端控制器
 * </p>
 *
 * @author 汤小洋
 * @since 2023-07-20
 */
@Api(tags = "员工表接口")
@RestController
@RequestMapping("/emp")
@RequiredArgsConstructor
public class EmpController {

    private final EmpService empService;

    @ApiOperation("分页查询员工表")
    @GetMapping("/{pageNum}/{pageSize}")
    public AjaxResult findByPage(@ApiParam("当前页") @PathVariable int pageNum,@ApiParam("页大小") @PathVariable int pageSize, Emp emp){
        IPage page = empService.findPage(pageNum,pageSize,emp);
        return AjaxResult.success(page);
    }

    @ApiOperation("按主键查询员工表")
    @GetMapping("/{id}")
    public AjaxResult getById(@ApiParam("学号") @PathVariable Serializable id){
        return AjaxResult.success(empService.getById(id));
    }

    @ApiOperation("新增员工表")
    @PostMapping
    public AjaxResult add(@RequestBody Emp stu){
        empService.save(stu);
        return AjaxResult.success();
    }

    @ApiOperation("修改员工表")
    @PutMapping
    public AjaxResult edit(@RequestBody Emp emp){
        empService.updateById(emp);
        return AjaxResult.success();
    }

    @ApiOperation("按主键删除员工表")
    @DeleteMapping("/{id}")
    public AjaxResult removeById(@ApiParam("学号") @PathVariable Serializable id){
        empService.removeById(id);
        return AjaxResult.success();
    }
}
